<?php

$my_server = array(
    "url" => "http://127.0.0.1:8080",
    "username" => "admin",
    "password" => "admin");

function xml_config_get($varname) {
    global $my_server;
    $url = $my_server{'url'}."/api/config/get";
    $params = "<parameters><varname>$varname</varname></parameters>";

    $response = http_post_data($url, $params,
        array(
            "httpauth" => $my_server{'username'}.':'.$my_server{"password"},
            "headers" => array(
                "Content-Type" => "text/xml"
            )
        ));
    list($headers, $response) = split("\r\n\r\n", $response, 2);
    $xml = simplexml_load_string($response);
    return $xml;
}

function json_config_get($varname) {
    global $my_server;
    $url = $my_server{'url'}."/api/config/get";
    $params = json_encode(array("varname"=>$varname));

    $response = http_post_data($url, $params,
        array(
            "httpauth" => $my_server{'username'}.':'.$my_server{"password"},
            "headers" => array(
                "Accept" => "text/javascript",
                "Content-Type" => "application/json",
            )
        ));
    list($headers, $response) = split("\r\n\r\n", $response, 2);
    $r = json_decode($response, true);
    return $r{'result'};
}

print "xml result = ".xml_config_get("company_name")."\n";
print "json result = ".json_config_get("company_name")."\n";

?>
